﻿package com.thorqq.magictimer.action;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.thorqq.magictimer.core.TimerAbs;

/**
 * 发送短信
 * 
 */
public class ActionPhone extends ActionSendSMS
{
    private static final long serialVersionUID = -7242249706432048530L;

    public ActionPhone(int id, int execOrder, String actionType, String param)
    {
        super(id, execOrder, actionType, param);
    }

    @Override
    public boolean run(Context context, TimerAbs timer)
    {
        this.paramToString();
                        
        //只给一个号码打电话
        for (String key : mPhoneNumber.keySet())
        {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            intent.setData(Uri.parse("tel:" + key));
            context.startActivity(intent);
            
            break;
        }


        return true;
    }

    @Override
    public String getName()
    {
        return "拨打电话";
    }

    @Override
    public String getDescription()
    {
        for (String key : mPhoneNumber.keySet())
        {
            String name = mPhoneNumber.get(key);
            if( name.length() > 0)
            {
                return name;
            }
            else
            {
                return key;
            }
        }
        
        return "点击选择被叫号码";
    }

}
